//
//  FTYPickerView.m
//  RedWine
//
//  Created by Liufangfang on 2017/1/2.
//  Copyright © 2017年 HuiBangKe. All rights reserved.
//

#import "FTYPickerView.h"

@interface FTYPickerView ()

@property (nonatomic, strong) UIPickerView *pickerV;

@end

@implementation FTYPickerView

#pragma mark - Init Method

- (id)init{
    
    self = [super init];
    if (self) {
        
        self.numberOfComponents = 1;
        [self setPicker];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.numberOfComponents = 1;
        [self setPicker];
    }
    return self;
}

#pragma mark - OverWrite Method

- (void)setTitleForRowArr:(NSArray *)titleForRowArr{
    
    _titleForRowArr = titleForRowArr;
}

#pragma mark - Set Method

- (void)setPicker{
    
    _pickerV = [[UIPickerView alloc] init];
    _pickerV.dataSource = self;
    _pickerV.delegate = self;
    [self addSubview:_pickerV];
}

#pragma mark - <UIPickerViewDataSource>

//当前显示的列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    
    return self.numberOfComponents;
}
//当前列显示的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    return self.titleForRowArr.count;
}
//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    NSLog(@"liufangfang=====%@", [self.titleForRowArr objectAtIndex:row]);
    _currentTitle = [self.titleForRowArr objectAtIndex:row];
    return [self.titleForRowArr objectAtIndex:row];
}

#pragma mark - <UIPickerViewDelegate>


#pragma mark - 修改组件上字体
//修改组件上字体
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:20]];
    }
    // Fill the label text here
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}

#pragma mark - Private Invoke Method

@end
